package GA;
import java.util.*;
import java.io.Serializable;

import Operations.Invoke;
	/**
	 * Manages method signatures.
	 */

	public class MethodDeclared implements Comparable<MethodDeclared> {
	  private final Class<?> cName;
	  private final String mName;
	  private final Class<?> returnType;
	  private final Class<?>[] paramsTpe;
	  private  Class<?> replacementObjectParam;
	  private final Map readRelatedMethods;
	  private final Map writeRelatedMethods;
	  private final boolean isStatic;
	
	  public MethodDeclared(Class cName,String mName, boolean isStatic, Class[] paramsTpe,Class returnType,Map writeRelatedMethods, Map readRelatedMethods) {
			this.cName = cName;
			this.mName = mName;
		    this.paramsTpe = paramsTpe;
		    this.returnType=returnType;
	  	    this.readRelatedMethods=readRelatedMethods;
		    this.writeRelatedMethods=writeRelatedMethods;
		    this.isStatic=isStatic;
		    this.replacementObjectParam=null;
		  }
	  public Class<?> getReplacementObjectParam(){
		  return this.replacementObjectParam;
	  }
	  public void setReplacementObjectParam(Class<?> clz){
		   this.replacementObjectParam=clz;
	  }
	  
	  public Class<?> getClazz(){
		  return this.cName;
	  }
	  public String getName() {
	    return mName;
	  }
	  public Class getReturnType() {
		    return returnType;
		  }
	  public Class[] getParameterTypes() {
	    return paramsTpe;
	  }
	  public Map getWriteRelatedMethods() {
		    return writeRelatedMethods;
		  }  
	  public Map getReadRelatedMethods() {
		    return readRelatedMethods;
		  }  
	  public boolean isStatic(){
		  return this.isStatic;
	  }

		@Override
		public int compareTo(MethodDeclared o) {

			final int compareName = mName.compareTo(o.mName);
			if(compareName != 0) return compareName;

			return 0;
		}
  @Override
  public MethodDeclared clone(){
		final MethodDeclared clone = new MethodDeclared( cName, mName,  isStatic,paramsTpe, returnType, writeRelatedMethods,  readRelatedMethods);
		return clone;
  }
	  
	  
	  @Override
		public String toString() {
			StringBuilder sb = new StringBuilder(mName).append("(");

			boolean first = true;
			for(Class<?> p : paramsTpe) {
				if(first) first = false;
				else sb.append(", ");

				sb.append(p.getName());
			}

			return sb.append(")").toString();
		}


	}

